var pageSize = 10;
var pageNum = 1;
var page;
var laypage;
var list;
var layer;


$(function () {
    $("#menuId").val(sessionStorage.menuId);
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        element = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层

        //以上模块根据需要引入


    });
    setTimeout(function () {
        fundAgentRank();
    },200);

});

//查询用户列表
function fundAgentRank() {
    var menuId = $("#menuId").val();
    var findType = $("#findType").val();
    var params = {
        "type":"query",
        "menuId":menuId,
        "pageSize":pageSize,
        "pageNum":pageNum,
        "findType":findType
    };
    $.ajax({
        type:"post",
        url:"/agent/findAgentRank",
        data:params,
        dataType:"json",
        success :function (data) {
            if(data.code == 1 && data.code != undefined){
                list = data.agentRankVos;
                page = data.page;
                var html = "";
                for(var b in list){


                    html += '<tr><td>'+list[b].userId+'</td>'+
                        '<td>'+list[b].phone+'</td>'+
                        '<td>'+list[b].agentLevelStr+'</td>'+
                        '<td>'+list[b].agentName+'</td>' +
                        '<td>'+list[b].rank+'</td>' +
                        '<td>'+list[b].order+'</td></tr>'
                    // console.log(html);
                }
                $("#bus").html(html);
                // $("#total").html("共有数据："+page.total+" 条");
                laypage({
                    cont: 'page'
                    ,pages: page.pages
                    ,first: 1
                    ,curr:pageNum
                    ,last: page.pages
                    ,prev: '<em><</em>'
                    ,next: '<em>></em>'
                    ,jump: function (obj,first) {
                        pageNum = obj.curr;
                        if(!first){
                            fundAgentRank();
                        }
                    }
                });
            }else if(data == 9999 && data != undefined){
                window.location.href = "/login_toLogin";
            }else if(data == 1111 && data != undefined){
                alert("无权操作");
            }
        }
    });
}

//查询按钮
function search() {
    pageNum = 1;
    fundAgentRank();
}